/*
  pins_arduino.h - Pin definition functions for Arduino

  Copyright (c) 2007 David A. Mellis

  This library is free software; you can redistribute it and/or
  modify it under the terms of the GNU Lesser General Public
  License as published by the Free Software Foundation; either
  version 2.1 of the License, or (at your option) any later version.

  This library is distributed in the hope that it will be useful,
  but WITHOUT ANY WARRANTY; without even the implied warranty of
  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  Lesser General Public License for more details.

  You should have received a copy of the GNU Lesser General
  Public License along with this library; if not, write to the
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  Boston, MA  02111-1307  USA


  Pin definition functions for Wiz200Web board
 
  Copyright (c) 2012 Alexander A. Chudov <chudov@gmail.com>
  
  Permission is hereby granted, free of charge, to any person 
  obtaining a copy of this software and associated documentation 
  files (the "Software"), to deal in the Software without restriction,
  including without limitation the rights to use, copy, modify, merge,
  publish, distribute, sublicense, and/or sell copies of the Software,
  and to permit persons to whom the Software is furnished to do so,
  subject to the following conditions:

  The above copyright notice and this permission notice shall be included
  in all copies or substantial portions of the Software.

  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 
  OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
  DEALINGS IN THE SOFTWARE.
*/

#ifndef Pins_Arduino_h
#define Pins_Arduino_h

#include <avr/pgmspace.h>

#define NUM_DIGITAL_PINS            34
#define NUM_ANALOG_INPUTS           8
#define analogInputToDigitalPin(p)  ((p < 8) ? (p) + 26 : -1)
#define digitalPinHasPWM(p)         (((p) >= 3 && (p) <= 5) || ((p) == 8) || ((p)== 9))

const static uint8_t SS   = 10;
const static uint8_t MOSI = 11;
const static uint8_t MISO = 12;
const static uint8_t SCK  = 13;

const static uint8_t SDA = 20;
const static uint8_t SCL = 21;
const static uint8_t LED_BUILTIN = 24;

const static uint8_t A0 = 26;
const static uint8_t A1 = 27;
const static uint8_t A2 = 28;
const static uint8_t A3 = 29;
const static uint8_t A4 = 30;
const static uint8_t A5 = 31;
const static uint8_t A6 = 32;
const static uint8_t A7 = 33;


#define digitalPinToPCICR(p)    ((uint8_t *)0))
#define digitalPinToPCICRbit(p) (0)
#define digitalPinToPCMSK(p)    ((uint8_t *)0))
#define digitalPinToPCMSKbit(p) (p)


#ifdef ARDUINO_MAIN

const uint16_t PROGMEM port_to_mode_PGM[] = {
	NOT_A_PORT,
	NOT_A_PORT,
	(uint16_t) &DDRB,
	NOT_A_PORT,
	(uint16_t) &DDRD,
	(uint16_t) &DDRE,
	(uint16_t) &DDRF,
	(uint16_t) &DDRG,
	NOT_A_PORT,
};

const uint16_t PROGMEM port_to_output_PGM[] = {
	NOT_A_PORT,
	NOT_A_PORT,
	(uint16_t) &PORTB,
	NOT_A_PORT,
	(uint16_t) &PORTD,
	(uint16_t) &PORTE,
	(uint16_t) &PORTF,
	(uint16_t) &PORTG,
};

const uint16_t PROGMEM port_to_input_PGM[] = {
	NOT_A_PIN,
	NOT_A_PIN,
	(uint16_t) &PINB,
	NOT_A_PIN,
	(uint16_t) &PIND,
	(uint16_t) &PINE,
	(uint16_t) &PINF,
	(uint16_t) &PING,
};

const uint8_t PROGMEM digital_pin_to_port_PGM[] = {
	// PORTLIST		
	// -------------------------------------------		
	PE,			//	PE 0 ** logical pin 0 ** (RX0)
	PE,			//	PE 1 ** logical pin 1 ** (TX0)
	PE,			//	PE 2 ** logical pin 2 ** 
	PE,			//	PE 3 ** logical pin 3 ** 
	PE,			//	PE 4 ** logical pin 4 ** 
	PE,			//	PE 5 ** logical pin 5 ** 
	PE,			//	PE 6 ** logical pin 6 ** 
	PE,			//	PE 7 ** logical pin 7 ** 

	PB,			//	PB 4 ** logical pin 8 ** 
	PB,			//	PB 5 ** logical pin 9 ** 
	PB,			//	PB 0 ** logical pin 10 ** (SS)
	PB,			//	PB 2 ** logical pin 11 ** (MOSI)
	PB,			//	PB 3 ** logical pin 12 ** (MISO)
	PB,			//	PB 1 ** logical pin 13 ** (SCK)
	PD,			//	PD 7 ** logical pin 14 ** 
	PD,			//	PD 6 ** logical pin 15 ** 

	PD,			//	PD 5 ** logical pin 16 ** 
	PD,			//	PD 4 ** logical pin 17 ** 
	PD,			//	PD 3 ** logical pin 18 ** 
	PD,			//	PD 2 ** logical pin 19 ** 
	PD,			//	PD 1 ** logical pin 20 ** 
	PD,			//	PD 0 ** logical pin 21 ** 
	PB,			//	PB 6 ** logical pin 22 ** 
	PB,			//	PB 7 ** logical pin 23 ** 

	PG,			//	PG 3 ** logical pin 24 **
	PG,			//	PG 4 ** logical pin 25 **
	
	PF,			//	PF 0 ** logical pin 26 ** A0
	PF,			//	PF 1 ** logical pin 27 ** A1
	PF,			//	PF 2 ** logical pin 28 ** A2
	PF,			//	PF 3 ** logical pin 29 ** A3
	PF,			//	PF 4 ** logical pin 30 ** A4
	PF,			//	PF 5 ** logical pin 31 ** A5
	PF,			//	PF 6 ** logical pin 32 ** A6
	PF,			//	PF 7 ** logical pin 33 ** A7
			
};
//_BOARD_WIZ200WEB_
const uint8_t PROGMEM digital_pin_to_bit_mask_PGM[] = {
	// PIN IN PORT		
	// -------------------------------------------		
	_BV( 0 )	, // PE 
	_BV( 1 )	, // PE 
	_BV( 2 )	, // PE 
	_BV( 3 )	, // PE 
	_BV( 4 )	, // PE 
	_BV( 5 )	, // PE 
	_BV( 6 )	, // PE 
	_BV( 7 )	, // PE 

	_BV( 4 )	, // PB 
	_BV( 5 )	, // PB 
	_BV( 0 )	, // PB 
	_BV( 2 )	, // PB 
	_BV( 3 )	, // PB 
	_BV( 1 )	, // PB 
	_BV( 7 )	, // PD 
	_BV( 6 )	, // PD 

	_BV( 5 )	, // PD 
	_BV( 4 )	, // PD 
	_BV( 3 )	, // PD 
	_BV( 2 )	, // PD 
	_BV( 1 )	, // PD 
	_BV( 0 )	, // PD
	_BV( 6 )	, // PB 
	_BV( 7 )	, // PB 

	_BV( 3 )	, // PG 
	_BV( 4 )	, // PG 

	_BV( 0 )	, // PF 
	_BV( 1 )	, // PF 
	_BV( 2 )	, // PF 
	_BV( 3 )	, // PF 
	_BV( 4 )	, // PF 
	_BV( 5 )	, // PF 
	_BV( 6 )	, // PF 
	_BV( 7 )	, // PF
};

const uint8_t PROGMEM digital_pin_to_timer_PGM[] = {
	// TIMERS		
	// -------------------------------------------		
	NOT_ON_TIMER,		//	PE 0 ** 0 ** (RX0)
	NOT_ON_TIMER	,	//	PE 1 ** 1 ** (TX0)
	NOT_ON_TIMER	,	//	PE 2 ** 2 ** 
	TIMER3A		,	//	PE 3 ** 3 ** 		OK
	TIMER3B		,	//	PE 4 ** 4 ** 		OK
	TIMER3C		,	//	PE 5 ** 5 ** 		OK
	NOT_ON_TIMER	,	//	PE 6 ** 6 ** 
	NOT_ON_TIMER	,	//	PE 7 ** 7 ** 

	TIMER0A		,	//	PB 4 ** 8 ** 		OK
	TIMER1A		,	//	PB 5 ** 9 ** 		OK
	NOT_ON_TIMER	,	//	PB 0 ** 10 ** 
	NOT_ON_TIMER	,	//	PB 2 ** 11 ** 
	NOT_ON_TIMER	,	//	PB 3 ** 12 ** 
	NOT_ON_TIMER	,	//	PB 1 ** 13 ** 
	NOT_ON_TIMER	,	//	PD 7 ** 14 ** 
	NOT_ON_TIMER	,	//	PD 6 ** 15 ** 

	NOT_ON_TIMER	,	//	PD 5 ** 16 ** 
	NOT_ON_TIMER	,	//	PD 4 ** 17 ** 
	NOT_ON_TIMER	,	//	PD 3 ** 18 ** 
	NOT_ON_TIMER	,	//	PD 2 ** 19 ** 
	NOT_ON_TIMER	,	//	PD 1 ** 20 ** 
	NOT_ON_TIMER	,	//	PD 0 ** 21 ** 
	NOT_ON_TIMER	,	//	PB 6 ** 22 ** 
	NOT_ON_TIMER	,	//	PB 7 ** 23 ** 

	NOT_ON_TIMER	,	//	PG 3 ** 24 ** 
	NOT_ON_TIMER	,	//	PG 4 ** 25 ** 
			
	NOT_ON_TIMER	,	//	PF 0 ** 26 ** ANALOG 0
	NOT_ON_TIMER	,	//	PF 1 ** 27 ** ANALOG 1
	NOT_ON_TIMER	,	//	PF 2 ** 28 ** ANALOG 2
	NOT_ON_TIMER	,	//	PF 3 ** 29 ** ANALOG 3
	NOT_ON_TIMER	,	//	PF 4 ** 30 ** ANALOG 4
	NOT_ON_TIMER	,	//	PF 5 ** 31 ** ANALOG 5
	NOT_ON_TIMER	,	//	PF 6 ** 32 ** ANALOG 6
	NOT_ON_TIMER	,	//	PF 7 ** 33 ** ANALOG 7
};

#endif

#endif